const path = require('path');
const fs = require('fs');

module.exports = {
  configureWebpack: config => {
    if (process.env.NODE_ENV === 'production') {
      //生成环境

    } else {
      //开发环境
      return {
        resolve: {
          alias: {
            '@js': path.resolve(__dirname, './src/assets/js'),
            '@css': path.resolve(__dirname, './src/assets/css'),
            '@img': path.resolve(__dirname, './src/assets/imgs'),
            '@c': path.resolve(__dirname, './src/components'),

          }
        },
        //配置接口
        devServer: {
          before(app) {
            app.get('/api/swiper', function (req, res) {
              fs.readFile(path.resolve(__dirname, 'src/assets/api/swiper.json'), 'utf8', function (err, data) {
                res.json(JSON.parse(data.trim()));
              })
            });
            app.get('/api/activitys', function (req, res) {
              fs.readFile(path.resolve(__dirname, 'src/assets/api/activitys.json'), 'utf8', function (err, data) {
                res.json(JSON.parse(data.trim()));
              })
            });
            app.get('/api/seconds',function (req,res) {
              fs.readFile(path.resolve(__dirname,'src/assets/api/seconds.json'),'utf8',function(err,data){
                res.json(JSON.parse(data.trim()));
              })
            });
            app.get('/api/goods',function (req,res) {
              fs.readFile(path.resolve(__dirname,'src/assets/api/goods.json'),'utf8',function(err,data){
                res.json(JSON.parse(data.trim()));
              })
            });
          }
        }
      }
    }
  }
}
